
#include"comm.hpp"

int main()
{
    int n = mkfifo(FIFO_FILE, 0664);
    if(n < 0)
    {
        perror("mkfifo");
        exit(FiFO_CREAT_ERR);
    }

    int fd = open(FIFO_FILE, O_RDONLY);
    if(fd < 0)
    {
        perror("open");
        exit(FIFO_OPEN_ERR);
    }
    while(true)
    {
        char buffer[1024] = {0};
        int x = read(fd, buffer, sizeof(buffer));
        if(x > 0)
        {
            buffer[x] = 0;
            std::cout << "client say#" << buffer << std::endl;
        }
        else if(x == 0)
        {
            std::cout << "client quit, me too!\n" <<std::endl;
            break;
        }
        else break;
    }
    close(fd);
    sleep(5);
    int m = unlink(FIFO_FILE);
    if(m < 0)
    {
        perror("unlink");
        exit(FIFO_DELETE_ERR);
    }
    return 0;
}